package com.itheima.controller;

import com.itheima.config.OssClient;
import com.itheima.pojo.Result;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@Slf4j
@RestController
@RequestMapping("/upload")
public class UploadController {
    @Resource
    OssClient ossClient;

    /**
     * MultipartFile Spring封装的用于接收文件的对象
     */
    @PostMapping
    public Result upload(MultipartFile file) {
        //调用工具类,将文件上传至云服务器,并获取文件的下载地址
        String url = ossClient.upload(file);
        return Result.success("上传成功",url);
    }
}
